/*
 *--------------------------------------------------------------------------
 *   Battlefield - A Realtime Network Multiplayer Game
 *   =======================================================
 *   Developed by Group D02 - 2009/2010 Semester 4 - CS2103
 *     Harry Nguyen Duy Hoang <nnduyhoang@yahoo.co.uk>
 *     Kent Chng Siang Rong <fivefootway@gmail.com>
 *     Lim Yong Peng <limpeng1986@gmail.com>
 *     Loh Xiankun <u0807185@nus.edu.sg>
 *   Instructed by
 *     Dr. Damith C.Rajapakse <damith@gmail.com>
 *   =======================================================
 *   $Id: GameMenuScreen.java 658 2010-07-30 08:32:19Z Harry $
 *   $LastChangedDate: 2010-07-30 08:32:19 +0000 (Fri, 30 Jul 2010) $
 *   $LastChangedBy: Harry $
 *--------------------------------------------------------------------------
 */
package battlefield.ui.screen;

import battlefield.resource.Graphics;
import battlefield.resource.Music;
import battlefield.ui.component.GameMenuButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.JButton;

/**
 *
 * @author Yong Peng
 */
public class GameMenuScreen extends Screen implements ActionListener {

    JButton startGameBut;
    JButton joinGameBut;
    JButton exitGameBut;
    JButton gameOptionBut;
    JButton tutorialBut;
    JButton creditBut;

    public GameMenuScreen() {
        initComponent();
    }

    private void initComponent() {
        startGameBut = new GameMenuButton("Create Game", this);
        joinGameBut = new GameMenuButton("Join Game", this);
        gameOptionBut = new GameMenuButton("Game Option", this);
        tutorialBut = new GameMenuButton("Tutorials", this);
        creditBut = new GameMenuButton("Credits", this);
        exitGameBut = new GameMenuButton("Exit Game", this);

        this.setBackgroundImage(Graphics.BACKGROUND_HOME.getImage());
        GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);
        layout.setAutoCreateGaps(true);
        layout.setAutoCreateContainerGaps(true);
        layout.setHorizontalGroup(
                layout.createSequentialGroup().addGap(65, 65, 65).addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(startGameBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(joinGameBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(gameOptionBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(tutorialBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(creditBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(exitGameBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)));
        layout.setVerticalGroup(
                layout.createSequentialGroup().addGap(59, 59, 59).addComponent(startGameBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addGap(10, 10, 10).addComponent(joinGameBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addGap(10, 10, 10).addComponent(gameOptionBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addGap(10, 10, 10).addComponent(tutorialBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addGap(10, 10, 10).addComponent(creditBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addGap(10, 10, 10).addComponent(exitGameBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE));

        this.setVisible(true);
        if (!Music.GAME_MENU.isRunning()) {
            Music.GAME_MENU.start();
        }
    }

    /* Begin Region: State Pattern */
    @Override
    public Screen createNewGame() {
        return new GameCreationScreen();
    }

    @Override
    public Screen joinNetworkGame() {
        return new JoinGameScreen();
    }

    @Override
    public Screen showTutorials() {
        return new TutorialScreen();
    }

    @Override
    public Screen showCredits() {
        return new CreditScreen();
    }

    @Override
    public Screen showOptions() {
        return new GameOptionScreen();
    }

    /* End Region: State Pattern */

    public void actionPerformed(ActionEvent e) {
        if (e.getSource().equals(startGameBut)) {
            getGUI().createNewGame();
        } else if (e.getSource().equals(joinGameBut)) {
            getGUI().joinNetworkGame();
        } else if (e.getSource().equals(gameOptionBut)) {
            getGUI().showOptions();
        } else if (e.getSource().equals(tutorialBut)) {
            getGUI().showTutorials();
        } else if (e.getSource().equals(creditBut)) {
            getGUI().showCredits();
        } else if (e.getSource().equals(exitGameBut)) {
            System.exit(0);
        }
    }
}
